home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / util / cdity / IFX.lha / IFX / AmigaE / play / play_dt.e < prev    next >
Text File  |  1997-12-03  |  2KB  |  92 lines

  1. ->
  2. -> sound.m - simplify playing sounds in E
  3. ->
  4.  
  5. MODULE 'devices/audio'
  6. MODULE 'exec/ports', 'exec/lists', 'exec/io', 'exec/execbase', 'exec'
  7. MODULE 'datatypes/datatypes', 'datatypes/datatypesclass', 'datatypes'
  8. MODULE 'dos', 'dos/dos'
  9. MODULE 'utility/tagitem'
  10. MODULE 'datatypes/soundclass'
  11.  
  12. DEF datatypesbase
  13.  
  14. PROC main()
  15.     play_dt(arg)
  16. ENDPROC
  17.  
  18. -> NAME
  19. ->     play_dt -- plays a sound file using datatypes.
  20. ->
  21. -> SYNOPSIS
  22. ->    play_dt(file)
  23. ->    :LONG   :PTR TO CHAR
  24. ->
  25. -> FUNCTION
  26. ->    This is a pretty simple-to-use function.  It is only an intermediate
  27. -> to my planned sound object.
  28. ->
  29. -> INPUTS
  30. ->    file (STRING)
  31.  
  32. PROC play_dt(file)
  33.     DEF play:dttrigger, sound
  34.     DEF num
  35.     DEF length, cycles, vh:voiceheader, time
  36.     DEF period, frequency
  37.     DEF eb:PTR TO execbase
  38.     DEF close
  39.     
  40.     play.methodid := DTM_TRIGGER
  41.     play.function := STM_PLAY
  42.  
  43.         -> If they haven't opened the datatypes library for us, then
  44.         -> we'll open it.
  45.     IF (datatypesbase = NIL)
  46.         datatypesbase := OpenLibrary('datatypes.library', 39)
  47.         close := 1
  48.     ENDIF
  49.  
  50.     sound := NewDTObjectA(file,
  51.         [
  52.         DTA_GROUPID,     GID_SOUND,    -> Only take sound files
  53.         SDTA_VOLUME,     64,            -> This might later be configurable
  54.         SDTA_CYCLES,    1,
  55.         TAG_END])
  56.  
  57.     IF sound
  58.         -> We will return the time to Delay(), if they need it.
  59.         GetDTAttrsA(sound,
  60.             [SDTA_SAMPLELENGTH, {length},
  61.             SDTA_PERIOD,         {period},
  62.             SDTA_CYCLES,        {cycles},
  63.             TAG_END])
  64.         
  65.         eb := execbase
  66.         frequency     := Mul(period, (357959465*2))
  67.         WriteF('Frequency = \d\n', frequency)
  68.         time        := (((length * cycles) * 50) / frequency)
  69.         WriteF('Time = \d\n', time)
  70.  
  71.         -> Play the sound.
  72.         DoDTMethodA(sound, NIL, NIL, play)
  73.     
  74.         -> Wait for it to finish.
  75.         Delay(time)
  76.         
  77.         -> Free the DT Object.
  78.         DisposeDTObject(sound)
  79.  
  80.     ELSE -> Unable to create DT object!
  81.         -> They're expecting a time, so zero is an error.  If they don't
  82.         -> check for an error, then no sample will play, so nothing will
  83.         -> will happen.
  84.         time := NIL
  85.     ENDIF
  86.     IF close
  87.         CloseLibrary(datatypesbase)
  88.         datatypesbase := NIL
  89.     ENDIF
  90. ENDPROC time
  91.  
  92.